package com.yang.booking.controller;

import com.yang.booking.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class ItemController {

    @Autowired
    private ItemService itemService;

    @PostMapping("/provider/item/insertItem")
    public Map<String, Object>  insertItem(@RequestParam(name = "storeId") String storeId,
                                               @RequestParam(name = "no") String no,
                                               @RequestParam(name = "name") String name,
                                               @RequestParam(name = "typeId") String typeId,
                                               @RequestParam(name = "price") String price,
                                               @RequestParam(name = "duration") String duration,
                                               @RequestParam(name = "pictureList") String pictureList,
                                               @RequestParam(name = "thumbnail") String thumbnail,
                                               @RequestParam(name = "videoList") String videoList,
                                               @RequestParam(name = "details") String details,
                                               @RequestParam(name = "shelf") String shelf,
                                               @RequestParam(name = "appointment") String appointment
    ){
        return itemService.insertItem(storeId, no, name, typeId,
                Float.parseFloat(price), Integer.parseInt(duration), pictureList, thumbnail, videoList,
                details, Integer.parseInt(shelf), Integer.parseInt(appointment));
    }

    @PostMapping("/provider/item/queryItemAll")
    public Map<String, Object>  queryItemAll(@RequestParam(name = "storeId") String storeId,
                                             @RequestParam(name = "nameOrNo") String nameOrNo,
                               @RequestParam(name = "typeId") String typeId,
                               @RequestParam(name = "shelf") String shelf,
                               @RequestParam(name = "appointment") String appointment,
                               @RequestParam(name = "pageSize") String pageSize,
                               @RequestParam(name = "pageNo") String pageNo
    ){
        return itemService.queryItemAll(storeId, nameOrNo, typeId, shelf, appointment, pageSize, pageNo);
    }

    @PostMapping("/provider/item/updateItemAppointment")
    public Map<String, Object> updateItemAppointment(@RequestParam(name = "itemIdList") String itemIdList,
                                        @RequestParam(name = "appointment") String appointment
    ){
        return itemService.updateItemAppointment(itemIdList, appointment);
    }

    @PostMapping("/provider/item/queryStaffItem")
    public Map<String, Object>  queryStaffItem(@RequestParam(name = "staffId") String staffId,
                                            @RequestParam(name = "nameOrNo") String nameOrNo,
                                         @RequestParam(name = "typeId") String typeId,
                                         @RequestParam(name = "select") String select,
                                         @RequestParam(name = "pageSize") String pageSize,
                                         @RequestParam(name = "pageNo") String pageNo
    ){
        return itemService.queryStaffItem(staffId, nameOrNo, typeId, select, pageSize, pageNo);
    }
}
